package com.burstly.lib.component.networkcomponent.burstly.html.mraid;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.SparseArray;
import com.burstly.lib.component.networkcomponent.burstly.html.IDestroyableActivityLifecycleAware;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.UiSafeWebView;

final class MraidEventBus<T extends MraidView,  extends IDestroyableActivityLifecycleAware> extends Handler
{
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final String TAG = MraidEventBus.class.getSimpleName();
  private volatile boolean mCleanedUp;
  private final SparseArray<MraidEvent> mEventsCache = new SparseArray();
  private final T mMraidView;

  MraidEventBus(T paramT)
  {
    this(paramT, Looper.myLooper());
  }

  MraidEventBus(T paramT, Looper paramLooper)
  {
    super(paramLooper);
    this.mMraidView = paramT;
    registerEvents();
  }

  private void registerEvents()
  {
    this.mEventsCache.put(0, new ReadyEvent());
    this.mEventsCache.put(1, new OpenEvent());
    this.mEventsCache.put(2, new CloseEvent());
    this.mEventsCache.put(3, new ExpandEvent());
    this.mEventsCache.put(4, new VisibilityChangedEvent());
    this.mEventsCache.put(5, new WindowEvent());
    this.mEventsCache.put(6, new PageLoadStartedEvent());
    this.mEventsCache.put(7, new SizePositionEvent());
    this.mEventsCache.put(8, new AddCalendarEvent());
    this.mEventsCache.put(9, new AddAssetEvent());
    this.mEventsCache.put(10, new ResizeEvent());
    this.mEventsCache.put(11, new PlayVideoEvent());
    this.mEventsCache.put(12, new OrientationRequestedEvent());
  }

  void destroy()
  {
    this.mCleanedUp = true;
    int i = 0;
    int j = this.mEventsCache.size();
    while (i < j)
    {
      ((MraidEvent)this.mEventsCache.get(i)).cleanUp();
      i++;
    }
    this.mEventsCache.clear();
  }

  public void handleMessage(Message paramMessage)
  {
    super.handleMessage(paramMessage);
    if (this.mCleanedUp)
      return;
    MraidEvent localMraidEvent = (MraidEvent)this.mEventsCache.get(paramMessage.what);
    if (localMraidEvent != null)
      try
      {
        if (!this.mMraidView.wasDestroyed())
        {
          localMraidEvent.fireEvent(this.mMraidView, (Object[])paramMessage.obj);
          return;
        }
      }
      catch (Exception localException)
      {
        LOG.logThrowable(TAG, localException);
        return;
      }
    LoggerExt localLoggerExt = LOG;
    String str = TAG;
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = Integer.valueOf(paramMessage.what);
    localLoggerExt.logWarning(str, "Event with {0} is not registered", arrayOfObject);
  }

  void sendEvent(int paramInt)
  {
    sendEvent(paramInt, null);
  }

  void sendEvent(int paramInt, Object[] paramArrayOfObject)
  {
    if (!this.mCleanedUp)
      obtainMessage(paramInt, paramArrayOfObject).sendToTarget();
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.html.mraid.MraidEventBus
 * JD-Core Version:    0.6.2
 */